import onTableBeforeEvent from '../request-functions/onTableBeforeEvent';

const batchAddSubTemplate = 'batchAddSub';
const batchAddSubTaleTemplate = 'batchAddSubTaleTemplate';

export default function(props, moduleId, key, index, value, record) {
    const {
        currentForm
    } = this.state;

    const {
        editTable: {
            getAllData,
            setTableData,
            setEditableRowKeyByIndex
        },
        func_type,
        pk_org,
        meta: {
            getMeta,
            setMeta
        }
    } = this.props;

    let template = getMeta();

    let postData = {
        areaCode: currentForm,
        func_type: func_type,
        key: key.attrcode, 
        model: {
            areaCode: currentForm,
            rows: getAllData(batchAddSubTaleTemplate)
        },
        pk_org: pk_org
    };

    onTableBeforeEvent(postData)
        .then((res) => {
            if(res.success) {
                let editTable = res.data.editTable;
                let param = res.data.refParam;
                
                setEditableRowKeyByIndex(batchAddSubTaleTemplate, index, key.attrcode, !editTable);
                template[batchAddSubTaleTemplate].items.map((item) => {
                    if(item.attrcode === key.attrcode) {
                        item['queryCondition'] = param;
                    }
                });
                setMeta(template);
            }
        })
        .catch((e) => {
        });

    return true;
}
